# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=pg_probackup
pkgver=2.5.15
_pgsqlver=17.0
_pgsqlverm="${_pgsqlver%%.[0-9]*}"
pkgrel=1
pkgdesc="Backup and recovery manager for PostgreSQL"
url="https://github.com/postgrespro/pg_probackup"
arch="all !riscv64 !loongarch64" # blocked by postgresql15
license="PostgreSQL"
makedepends="
	bison
	flex
	libxml2-utils
	libxslt
	perl
	postgresql$_pgsqlverm
	postgresql$_pgsqlverm-dev
	readline-dev
	zlib-dev
	"
source="pg_probackup-$pkgver.tar.gz::https://github.com/postgrespro/pg_probackup/archive/refs/tags/$pkgver.tar.gz
	https://ftp.postgresql.org/pub/source/v$_pgsqlver/postgresql-$_pgsqlver.tar.bz2"
builddir="$srcdir/postgresql-$_pgsqlver/contrib/pg_probackup-$pkgver"

prepare() {
	default_prepare

	mv "$srcdir"/pg_probackup-$pkgver "$srcdir"/postgresql-$_pgsqlver/contrib

	cd "$srcdir"/postgresql-$_pgsqlver
	./configure --without-ldap

	local header
	for header in $(ls "$srcdir"/postgresql-$_pgsqlver/src/bin/pg_basebackup/*.h); do
		ln -s $header "$builddir"/src/
	done
}

build() {
	make -j1

	# fail to build
	# cd doc
	# xmllint --noout --valid probackup.xml
	# xsltproc stylesheet.xsl probackup.xml >pg-probackup.html
}

check() {
	local catalog="$PWD$(mktemp -u)"

	./pg_probackup version
	./pg_probackup init -B "$catalog"
}

package() {
	install -Dm755 ./pg_probackup \
		"$pkgdir"/usr/bin/pg_probackup$_pgsqlverm
	# install -Dm644 "$builddir"/doc/pg-probackup.html "$pkgdir"/usr/share/doc/pg_probackup/pg-probackup.html
}

sha512sums="
10c241397895824db63a9f374e375a1de99822cdd0b2573986e9b99ceda513b255bba8234a99a9cb26506f9177d501b0d4565a939848e92082da72431b69e79e  pg_probackup-2.5.15.tar.gz
ae6741298abe986c9f09a6eee9fa2df26c3bbdffcbd0ff3f33332456e09f95195e4535f00a9437f2877e03e2e43a78be9a355303e7cf43bcb688b657ca7289f3  postgresql-17.0.tar.bz2
"
